using System;
using Xunit;
using Xunit.Abstractions;
using FrameIdentityReq.Frames;
using Exceptions;

namespace xUnitTest
{
    public class TestDateTimeField
    {

        [Theory]
        [InlineData("2010-1-1 0:0:0", 0, "ServerDateTime")]
        [InlineData("2012-12-31 9:0:0", 6, "ServerDateTime1")]
        [InlineData("2055-8-1 23:59:0", 7, "ServerDateTime2")]
        [InlineData("2073-1-1 23:59:59", 8, "ServerDateTime3")]
        [InlineData("2073-12-31 0:0:1", 9, "ServerDateTime4")]
        public void TestGeneral(string dateTimeString, int index, string name)
        {
            DateTime dateTime = DateTime.Parse(dateTimeString);
            BaseFrame frame = new IdentityAckFrame();
            DateTimeField field = new DateTimeField(frame, index, name);
            field.Value = dateTime;

            Assert.Equal(4 << 3, field.Count);
            Assert.Equal(6, field.Year.Count);
            Assert.Equal(4, field.Month.Count);
            Assert.Equal(5, field.Day.Count);
            Assert.Equal(5, field.Hour.Count);
            Assert.Equal(6, field.Minute.Count);
            Assert.Equal(6, field.Second.Count);

            Assert.Equal(index, field.Index);
            Assert.Equal(name, field.Name);
            Assert.Equal(dateTime, field.Value);

            Assert.Equal(dateTime.Year, field.Year.Value + 2010);
            Assert.Equal(dateTime.Month, field.Month.Value);
            Assert.Equal(dateTime.Day, field.Day.Value);
            Assert.Equal(dateTime.Minute, field.Minute.Value);
            Assert.Equal(dateTime.Second, field.Second.Value);
        }

        [Theory]
        [InlineData("2009-12-31 23:59:59", 9, "ServerDateTime3")]
        [InlineData("2074-1-1 0:0:0", 9, "ServerDateTime4")]
        public void TestException(string dateTimeString, int index, string name)
        {
            DateTime dateTime = DateTime.Parse(dateTimeString);
            BaseFrame frame = new IdentityAckFrame();
            DateTimeField field = new DateTimeField(frame, index, name);

            Assert.Throws<ExceptionOverLength>(() => field.Value = dateTime);
        }
    }
}